<?php
/**
 * 分类
 *
 * @copyright  Copyright (c) 2015-2025 NcPHP Inc. (http://www.ncphp.com)
 * @license    http://www.ncphp.com/
 * @link       http://www.ncphp.com/
 * @author     NcPHP Team
 * @since      File available since Release v1.1
 */
defined('InNcPHP') or exit('Access Invalid!');

class cateControl extends BaseHomeControl{

    public function __construct(){
        parent::__construct();
    }

    /**
     * 分类页面
     */
    public function indexOp(){
        /* @var ticket_categoryModel $cate_model */
        $cate_model = Model('ticket_category');
        $cates = $cate_model->getCategoryList(array('is_del'=>0,'tc_pid'=>array('gt','0',)));//需要调整成不等于0，显示最全的分类

        foreach ($cates as $k => $cate) {
            $cates[$k]['tc_icon'] = UPLOAD . 'product/' . $cate['tc_icon'];
        }
        Tpl::output('cates', $cates);
        Tpl::showpage('cate.index');
    }

    /**
     * 二级分类页面
     */
    public function subOp()
    {
        /* @var ticket_categoryModel $cate_model */
        $cate_model = Model('ticket_category');
        /* @var ticketModel $ticket_model */
        $ticket_model = Model('ticket');

        //一级分类
        $pid = intval($_GET['pid']);
        $cates = $cates = $cate_model->getCategoryList(array('is_del'=>0,'tc_pid'=>$pid));
        $cate_info = $cate_model->getCategoryInfo(array('tc_id'=>$pid,'is_del'=>0),'tc_name');
        Tpl::output('cate_name',$cate_info['tc_name']);
        Tpl::output('cates', $cates);

        //二级分类
        $id = intval($_GET['id']);
        if (!$id) {
            $id = $cates[0]['tc_id'];
        }

        $fields = implode(',',array(
            'tk_id',
            'tk_title',
            'tk_subtitle',
            'tk_type',
            'tk_cate2',
            'tk_city_name',
            'tk_subtitle',
            'tk_thumb',
            'tk_show_price',
            'tk_market_price',
            'tk_city_id',
            'tk_status',
        ));
        $condition = array(
            //'tk_city_id'=>$_SESSION['pos']['city_id'],
            'tk_cate1'=>$pid,
            //'tk_cate2' => $id,
            'tk_status' => 1,
        );
        $tickets = $ticket_model->getTicketListPage($condition, $fields, 10);
        foreach ($tickets as $k=>$ticket) {
            $tickets[$k]['tk_thumb'] = UPLOAD.'product/'.$ticket['tk_thumb'];
        }
        Tpl::output('tickets', $tickets);

        //AJAX加载分页
        if (isset($_GET['isajax']) && $_GET['isajax'] == 1) {
            Tpl::showpage('cate.subcate.page', 'null_layout');
            exit;
        }

        Tpl::output('TotalNum', pagecmd("gettotalnum"));
        Tpl::output('TotalPage', pagecmd("gettotalpage"));

        Tpl::output('id', $id);
        Tpl::showpage('cate.subcate');
    }
}
